package clientMain;

import java.io.IOException;
import java.net.Socket;
import java.net.UnknownHostException;
import java.util.Scanner;
import lib.StreamSocket;

public class Client {

	/**
	 * 
	 * @param args
	 */
	public static void main(String[] args) {
		Receiver rx;
		Transmitter tx;
		Scanner scan = new Scanner(System.in);
		boolean debug = false;
		boolean hostAccepted = true;
		String URI;
		String host;
		Socket requestSocket;
		StreamSocket streamServer;

		System.out.print("Debug mode Y/n?\n");
		if (scan.next().equalsIgnoreCase("Y")) {
			debug = true;
		}

		URI = scan.next();
		host = Parser.getHost(URI);
		if (URI.equals("")) {
			host = "localhost";
		}
		try {
			requestSocket = new Socket(host, 3434);
			streamServer = new StreamSocket(requestSocket);
			rx = new Receiver(streamServer, debug);
			tx = new Transmitter(streamServer, scan, URI, debug);
			rx.start();
			tx.start();
		} catch (UnknownHostException e) {
			System.out.print("Host not found\n");

		} catch (IOException e) {
			e.printStackTrace();
		}
	}
}
